﻿using System;
using GeoAPI.Geometries;

namespace NetTopologySuite.Index.KdTree
{
	public class KdNode<T> where T : class
	{
		public KdNode(double x, double y, T data)
		{
			this._p = new Coordinate(x, y);
			this.Left = null;
			this.Right = null;
			this._count = 1;
			this._data = data;
		}

		public KdNode(Coordinate p, T data)
		{
			this._p = new Coordinate(p);
			this.Left = null;
			this.Right = null;
			this._count = 1;
			this._data = data;
		}

		public double X
		{
			get
			{
				return this._p.X;
			}
		}

		public double Y
		{
			get
			{
				return this._p.Y;
			}
		}

		public Coordinate Coordinate
		{
			get
			{
				return this._p;
			}
		}

		public T Data
		{
			get
			{
				return this._data;
			}
		}

		public KdNode<T> Left { get; set; }

		public KdNode<T> Right { get; set; }

		internal void Increment()
		{
			this._count++;
		}

		public int Count
		{
			get
			{
				return this._count;
			}
		}

		public bool IsRepeated
		{
			get
			{
				return this._count > 1;
			}
		}

		private readonly Coordinate _p;

		private readonly T _data;

		private int _count;
	}
}
